//run environment
//$Id: run_environment.h 605 2010-11-27 15:10:07Z Oleg.Bulychov $
#pragma once

#include "src/heo/include/xml_file.h"
#include "src/heo/include/statistics.h"

namespace hidden
{

template<class P, class S, class C>
struct run
{
    typedef P TProblem;
    typedef S TSolution;
    typedef C TConfig;

    std::string input_file_; 
    std::string output_dir_;
    size_t      output_size_;
    std::string initial_solution_;
    int         run_count_;
    int         rand_seed_;
    //int         anytime_rate_;
    int         debug_level_;

    static char const* get_Name() { return "run"; }
    static char const* get_Section() { return get_Name(); }//: <run> xml node

    template<class V>
    void accept(V& v)
    {
        char const* def_file = TProblem::get_Default_File_Name();
        std::string s;
        if (def_file && *def_file)
        {
            s = "../../../problems/";
            s += TConfig::get_Name();
            s += "/";
            s += def_file;
        }
        v(VAR_(input_file),                 s.c_str());
        s = "../res/";
        if (def_file && *def_file)
        {
            s += def_file;
            //:strip .ext
            size_t ext = s.rfind('.');
            if (ext != std::string::npos)
                s.erase(ext);
            s += "/";
        }
        //s += TSolver::get_Output_Folder_Name();
        v(VAR_(output_dir),                 s.c_str());
        v(VAR_(output_size),                1);
        v(VAR_(initial_solution),           "");
        v(VAR_(run_count),                  1);
        //v(VAR_(rand_seed),                  1100101);
        //v(VAR_(anytime_rate),               0);
        v(VAR_(debug_level),                0);
    }
};

}

template<class P, class S, class C, class Stat = Statistics>
struct Environment:
    public hidden::run<P, S, C>
{
    typedef P TProblem;
    typedef S TSolution;
    typedef C TConfig;
    typedef Stat TStatistics;

    TConfig     cfg_;
    TProblem    problem_;

    xml::file   property_tree_;
    double      start_time_;

    static char const* get_Name() { return "env"; }
    static char const* get_Section() { return "/"; }//: root xml node

    template<class V>
    void accept(V& v)
    {
        v((hidden::run<P, S, C>&)*this);
        v(cfg_, "");
    }
};

//EOF!
